package net.zjitc.service.impl;


import net.zjitc.mapper.GoodsMapper;
import net.zjitc.pojo.Category;
import net.zjitc.pojo.Goods;

import net.zjitc.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;
    @Override

    public List<Goods> findAll() {
        List<Goods> goodsList = goodsMapper.findAll();
        return goodsList;
    }

    @Override
    public Map<String, Object> findAllWithPagination(int page, int pagesize) {
        int offset = (page - 1) * pagesize;
        List<Goods> goodsList = goodsMapper.findAllWithPagination(offset, pagesize);
        int total = goodsMapper.countTotal();
        Map<String, Object> result = new HashMap<>();
        result.put("data", goodsList);
        result.put("total", total);
        return result;
    }

    @Override
    public void insertShop(Goods goods) {
        goodsMapper.insertShop(goods);
    }


    @Override
    public int delete(Integer id) {
        int i = goodsMapper.delete(id);
        return i;
    }

    @Override
    public Goods findById(Integer id) {
        Goods goods = goodsMapper.findById(id);
        return goods;
    }

    @Override
    public void update(Goods goods) {
        goodsMapper.update(goods);
    }


}
